﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using SigMIS.Model;


namespace SigMIS.ViewModel.Equipment.MapVMs
{
    public partial class MapVM : BaseVM
    {
        [Display(Name = "选择线路")]
        public string SelectedRoadLine { get; set; }    

        public List<string> RoadLineItems { get; set; }

        public List<Selected_RoadLine_Item> RoadLinePoints { get; set; }
        public MapVM()
        {
        }

        protected override void InitVM()
        {
            DoRefreshRoadLines();
            DoSelectRoadLine();
        }

        public void DoSelectRoadLine()
        {
            //选择线路(GPS经纬度点）

            RoadLinePoints = DC.Set<RoadLine>().Where(x => x.RoadLineName == SelectedRoadLine && x.Longitude > 0 && x.Latitude > 0)
                .Select(x => new Selected_RoadLine_Item
                {
                    ID = x.ID,
                    Longitude = x.Longitude / 100.0,
                    Latitude = x.Latitude / 100.0,
                    StationName = x.StationName,
                }).ToList();

            Console.WriteLine(RoadLinePoints.Count());
        }
        
        public void DoRefreshRoadLines()
        {
            //刷新线路列表
            var grouplist = DC.Set<RoadLine>().AsEnumerable<RoadLine>().GroupBy(x => x.RoadLineName);
            if (grouplist != null)
                
            RoadLineItems = new List<string>();
            foreach (var item in grouplist)
            {
                RoadLineItems.Add(item.Key);                    
            }

            if (RoadLineItems.Count > 0)
                SelectedRoadLine = RoadLineItems[0];
        }
    }

    public class Selected_RoadLine_Item :TopBasePoco
    {

        [Display(Name = "经度")]
        public double Longitude { get; set; }

        [Display(Name = "纬度")]
        public double Latitude { get; set; }

        [Display(Name = "车站名称")]
        public String StationName { get; set; }
    }

}
